import json


# 定义用户信息类 UserInfo
class UserInfo:
    def __init__(self, name, age, email):
        self.name = name
        self.age = age
        self.email = email

    def __str__(self):
        return f"Name: {self.name}, Age: {self.age}, Email: {self.email}"


# 读取 JSON 文件并处理用户信息
def read_json_file(filename):
    user_info_list = []

    try:
        with open(filename, 'r') as file:
            data = json.load(file)
            for user_data in data:
                # 提取用户信息
                name = user_data.get('name', '')
                age = user_data.get('age', 0)
                email = user_data.get('email', '')

                # 创建 UserInfo 对象并添加到列表中
                user_info = UserInfo(name, age, email)
                user_info_list.append(user_info)

    except FileNotFoundError:
        print(f"File '{filename}' not found.")

    return user_info_list


# 遍历输出所有用户信息
def print_user_info(user_info_list):
    for user_info in user_info_list:
        print(user_info)
        print()  # 打印空行分隔每个用户信息


# 主函数
def main():
    filename = "json.txt"  # 假定 json.txt 位于与脚本相同的目录下
    user_info_list = read_json_file(filename)

    if user_info_list:
        print("User Information:")
        print_user_info(user_info_list)
    else:
        print("No user information found.")


# 执行主函数
if __name__ == "__main__":
    main()
